// UI模块
pub mod cli;
pub mod interactive;
pub mod progress;

use anyhow::Result;
use crate::ftp_client::FtpClient;

/// UI管理器
pub struct UiManager {
    cli: cli::CliInterface,
    interactive: Option<interactive::InteractiveInterface>,
    progress: progress::MultiTransferDisplay,
}

impl UiManager {
    pub fn new() -> Self {
        Self {
            cli: cli::CliInterface::new(),
            interactive: None,
            progress: progress::MultiTransferDisplay::new(),
        }
    }

    pub fn with_colors(mut self, show_colors: bool) -> Self {
        self.cli = self.cli.with_colors(show_colors);
        self
    }

    pub fn with_progress(mut self, show_progress: bool) -> Self {
        self.cli = self.cli.with_progress(show_progress);
        self
    }

    pub fn with_verbose(mut self, verbose: bool) -> Self {
        self.cli = self.cli.with_verbose(verbose);
        self
    }

    /// 启动交互模式
    pub async fn start_interactive_mode(&mut self, client: FtpClient) -> Result<()> {
        let mut interactive = interactive::InteractiveInterface::new(client);
        interactive.run().await?;
        Ok(())
    }

    /// 显示帮助信息
    pub fn show_help(&self) {
        self.cli.show_help();
    }

    /// 显示版本信息
    pub fn show_version(&self) {
        self.cli.show_version();
    }

    /// 显示连接状态
    pub fn show_connection_status(&self, host: &str, port: u16, connected: bool) {
        self.cli.show_connection_status(host, port, connected);
    }

    /// 显示认证状态
    pub fn show_auth_status(&self, username: &str, authenticated: bool) {
        self.cli.show_auth_status(username, authenticated);
    }

    /// 显示目录信息
    pub fn show_directory_info(&self, path: &str) {
        self.cli.show_directory_info(path);
    }

    /// 显示文件列表
    pub fn show_file_list(&self, entries: Vec<String>) {
        self.cli.show_file_list(entries);
    }

    /// 显示传输进度
    pub fn show_transfer_progress(&self, filename: &str, transferred: u64, total: u64, speed: f64) {
        self.cli.show_transfer_progress(filename, transferred, total, speed);
    }

    /// 显示传输完成
    pub fn show_transfer_complete(&self, result: &crate::ftp_client::TransferResult) {
        self.cli.show_transfer_complete(result);
    }

    /// 显示错误信息
    pub fn show_error(&self, message: &str) {
        self.cli.show_error(message);
    }

    /// 显示警告信息
    pub fn show_warning(&self, message: &str) {
        self.cli.show_warning(message);
    }

    /// 显示信息
    pub fn show_info(&self, message: &str) {
        self.cli.show_info(message);
    }

    /// 显示成功信息
    pub fn show_success(&self, message: &str) {
        self.cli.show_success(message);
    }

    /// 显示调试信息
    pub fn show_debug(&self, message: &str) {
        self.cli.show_debug(message);
    }

    /// 显示传输统计
    pub fn show_transfer_stats(&self, stats: &cli::TransferStats) {
        self.cli.show_transfer_stats(stats);
    }

    /// 显示队列状态
    pub fn show_queue_status(&self, pending: usize, running: usize, completed: usize, failed: usize) {
        self.cli.show_queue_status(pending, running, completed, failed);
    }

    /// 获取进度显示器
    pub fn progress_display(&self) -> &progress::MultiTransferDisplay {
        &self.progress
    }

    /// 获取进度显示器（可变）
    pub fn progress_display_mut(&mut self) -> &mut progress::MultiTransferDisplay {
        &mut self.progress
    }
}
